"""
Defines constants and objects used in CtaStrategy App.
"""

from dataclasses import dataclass, field
from enum import Enum

from common.constant import Direction, Offset
from common.object import Status
from datetime import datetime

APP_NAME = "CtaStrategy"
STOPORDER_PREFIX = "STOP"
SPREADORDER_PREFIX = "SPREAD"


class StopOrderStatus(Enum):
    WAITING = "等待中"
    CANCELLED = "已撤销"
    TRIGGERED = "已触发"


class EngineType(Enum):
    LIVE = "实盘"
    BACKTESTING = "回测"


class BacktestingMode(Enum):
    BAR = 1
    TICK = 2
    MIXED = 3
    ArbMIXED = 4


@dataclass
class CommissionRate:
    open_commission_amount: float = 0
    open_commission_rate: float = 0
    close_commission_amount: float = 0
    close_commission_rate: float = 0
    close_today_commission_amount : float = 0
    close_today_commission_rate: float = 0


@dataclass
class StopOrder:
    vt_symbol: str
    direction: Direction
    offset: Offset
    price: float
    volume: float
    stop_orderid: str
    strategy_name: str
    lock: bool = False
    vt_orderids: list = field(default_factory=list)
    status: StopOrderStatus = StopOrderStatus.WAITING

@dataclass
class SpreadOrder:
    vt_symbol1: str
    vt_symbol2: str
    direction: Direction
    offset: Offset
    price: float
    volume: float
    spread_orderid: str
    strategy_name: str
    vt_orderids: list = field(default_factory=list)
    lock: bool = False
    status: Status = Status.SUBMITTING
    continuous_cross: int = 0


EVENT_CTA_LOG = "eCtaLog"
EVENT_CTA_STRATEGY = "eCtaStrategy"
EVENT_CTA_STOPORDER = "eCtaStopOrder"
